package org.streets.eis.component.foreigncombobox;

import java.io.Serializable;

import org.apache.wicket.util.string.Strings;

public class ForeignDefinition implements Serializable {
	
	private static final long serialVersionUID = 1L;

	private String idField;
	
	private String textField;

	private String parentField;
		
	private String tableName;
	
	private String conditionSql;
	
	private String orderSql;

	public ForeignDefinition(String idField,String textField,String tableName){
		this(idField,textField,tableName,"");
	}
	
	public ForeignDefinition(String idField,String textField,String tableName,String orderSql){
		this(idField,textField,tableName,orderSql,"");
	}	

	public ForeignDefinition(String idField,String textField,String tableName,String orderSql,String conditionSql){
		this(idField,textField,tableName,"",orderSql,conditionSql);
	}
	
	public ForeignDefinition(String idField,String textField,String tableName,String parentField,String orderSql,String conditionSql){
		this.idField = idField;
		this.textField = textField;
		this.tableName = tableName;
		this.parentField = parentField;
		this.orderSql = orderSql;
		this.conditionSql = conditionSql;		
	}
	
	public String getIdField() {
		return idField;
	}

	public ForeignDefinition setIdField(String idField) {
		this.idField = idField;
		return this;
	}

	public String getTextField() {
		return textField;
	}

	public ForeignDefinition setTextField(String textField) {
		this.textField = textField;
		return this;
	}

	public String getParentField() {
		return parentField;
	}

	public ForeignDefinition setParentField(String parentField) {
		this.parentField = parentField;
		return this;
	}

	public String getTableName() {
		return tableName;
	}

	public ForeignDefinition setTableName(String tableName) {
		this.tableName = tableName;
		return this;
	}

	public String getConditionSql() {
		return conditionSql;
	}

	public ForeignDefinition setConditionSql(String conditionSql) {
		this.conditionSql = conditionSql;
		return this;
	}
	
	public String getOrderSql() {
		return Strings.isEmpty(orderSql) ? idField : orderSql;
	}

	public ForeignDefinition setOrderSql(String orderSql) {
		this.orderSql = orderSql;
		return this;
	}	

}
